Part Number Hot Search : 
1N977B 170M3270 PSB21 60CTQ150 PM1205S BZX84C10 GBL206 ST72632
Product Description
Full Text Search
 

To Download AT42QTAN0040 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  driving the at42qt2160 qmatrix sensor ic 1. introduction this application note shows how the at42qt2160-mmu (qt2160) 16-key qmatrix? sensor ic can be connected to a microproc essor to provide touch input functionality. example code is provided to demonstrat e how easily the qt2160 can be incorporated into a design. the code can be run ?as is? or used as a starting point for qt2160- based projects. the example compiles to under 1 kbyte of code including all necessary i 2 c-compatible driver functions. the example code is written in the c programming language and can easily be adapted for many processor types. see section 6 on page 8 for a listing of the complete program. figure 1-1. circuit configuration for the example project 2. overview of the qt2160 2.1 introduction the qt2160 is designed for use with up to 16 keys and a slider (constructed from 2 keys up to 8 keys). there are three dedicated general-purpose input/outputs (gpio), which can be used as inputs (for example, for mechanical switches) or as driven outputs. there are eight shared general-purpose outputs (gpo). pulse switch modulation (pwm) control can be applied to all gpio and gpo pins. keys are configured in a matrix format that minimizes the number of required scan lines and device pins. the key electrodes can be designed into a conventional printed circuit board (pcb) or flexible printed ci rcuit board (fpcb) as a copper pattern, or as printed conductive ink on plastic film. the qt2160 can be fine tuned to optimize operation with the electrode design. full details of the qt2160 can be found in the qt2160 datasheet, which should be read in conjunction with this application note. host mcu vdd qmatrix key array 8 discrete keys (keys 8 15) ? 5-key slider (keys 0 4) ? p0.3 p0.6 p0.7 qt2160 vdd gpio3 gpo0 gpo1 gpo2 gpo3 sda scl change driving the at42qt2160 qmatrix sensor ic application note AT42QTAN0040 10702a?at42?07/08
2 10702a?at42?07/08 driving the at42qt2160 2.2 qt2160 host interface the qt2160 connects to a host controller by means of an i 2 c-compatible serial interface. this uses a common two-wire connection between the host qt2160 and other i 2 c-compatible devices in the system. the bus protocol takes ca re of all addressing functions and bidirectional data transfer. full deta ils can be found in the philips document ?the i 2 c-bus specification?. in addition, the qt2160 features a change pin, which can be used either to wake the host in a battery-powered application or as an interrupt signal to inform the host when the qt2160 status has changed. the change pin can be left unconnected in systems where the qt2160 is polled via the i 2 c-compatible bus on a regular basis. 2.3 qt2160 programming model all communication with the qt2160 takes place via a set of addressable, 8-bit registers. all read and write operations to the registers are made via the i 2 c-compatible bus. the protocol for performing reads and writes is based on that used for standard serial eeprom devices and is fully described in the qt2160 datasheet. the ex ample code presented in this application note includes a suitable i 2 c-compatible driver. 3. the example qt2160 project 3.1 introduction the example project shows how to use the host interface to read real-time touch information from the qt2160. it also shows how the discrete output pins of the qt2160 can be simultaneously driven to reflect the touch status. 3.2 circuit configuration figure 1-1 on page 1 shows the circuit used for this example. representative touch keys are connected to the x/y drive signals as described in the datasheet. the example uses a five-key slider comprising keys 0 ? 4, and eight discrete keys connected as keys 8 ? 15. connection to the host microcontroller uses the two i 2 c-compatible pins (scl and sda) and the change pin. the example uses leds on qt2160 pins gpo0 to gpo3 to indicate touches on keys 8 ? 11. it also uses an led on gpio3 to indicate the slider position by means of the pwm function. the following points should be noted: ? the qt2160 i 2 c-compatible slave address can be selected via pins i2ca1 and i2ca0. the demonstration program uses address 0x0d, whic h is selected by connecting i2ca1 = i2ca0 = vss. ? pull-up resistors are required on the i 2 c-compatible signals (scl and sda). either discrete pull-up resistors or the host microcontroller?s weak pull-ups can be used. ensure that the pull-up resistors are connected to the same vdd level as the qt2160. ?the change pin has open-drain characteristics and requires a pull-up resistor. ? leds are connected to the appropriate pins of the qt2160 using inverting buffers as described in the datasheet. the example code assumes the following port assignments on the host microcontroller: ? sda is connected to p0.6. ? scl is connected to p0.7. ?change is connected to p0.3.
3 10702a?at42?07/08 driving the at42qt2160 3.3 interface timing figure 3-1 illustrates the interface timing used in t he example. the qt2160 signals any change in its sense status by driving the change pin low. in this context, sense status includes bytes 2 through 6 of the address map. in response to the qt2160 driving change low, the host reads all of bytes 2 ? 6. the qt2160 releases the change pin when all changed bytes have been read. handshaking logic within the qt2160 guarantees that any unread changes in any status byte will cause change to be driven low, even if this o ccurs while the devi ce is being read. figure 3-1. qt2160 interface timing 4. demonstration program 4.1 the main() function a simplified flowchart for the qt2160 demonstration program is shown in figure 4-1 . the program flow is encapsulated in the main() function of the c code (see section 6 on page 8 ). figure 4-1. simplified flowchart for the demonstration program status read status read status read i2c-comaptible change in status cleared by read change in status during read cleared by following read change main() establish comms to qt2160 read qt2160 status display status on leds low high change pin? initialize qt2160 no yes res set?
4 10702a?at42?07/08 driving the at42qt2160 during initialization, the program establishes communication with the qt2160 and then sets it up for the required operating mode. in the main loop, the program monitors the change pin. if the change pin is low, the program reads the five status bytes. it then writes the state of the discrete keys back to the qt2160 pins gpo0 to gpo3 and writes the slider position back to the pwm driver for gpio3. the effect of touching the keys and slider is thus displayed on leds connected to i/o pins of the qt2160. 4.2 qt2160 initialization initialization occurs at the start of the main() function, as follows: 1. the demonstration program establishes the initial communication with qt2160 by reading its chip-id. the qt21 60 takes several milliseconds to initialize itself after power-up. during this time, it may not acknowledge (ack) its slave address. the writeqti2c() function repeatedly attempts to send the slave address until the ack is received. 2. once the device has been read successfully, the returned chip id is checked. if the wrong id is returned, the demonstration program goes no further. depending on the construction of the touch keys being used, it may be necessary to adjust the touch-related registers. this should be done in the initialization code. 4.3 main loop following initialization, th e remainder of the main() function consists of a main loop, as follows: 1. the state of the change pin is sampled. 2. if change is asserted low, the status registers (addresses 2 ? 6) are read into the five-byte qtstatus[] array. reading these registers restores the change pin to the inactive (high) state. 3. if the res bit in the ?general status? register is set, indicating that the qt2160 has been reset, the device is initialized. this will occur after initial power up but may also occur if, for example, the rst pin is pulled low at any time. the demonstration program changes a few registers from their default values. note that all the qt2160?s registers are set to default values every time the device is reset (refer to the qt2160 datasheet for the default values). the demonstration program makes the following changes: a. gpio3 is set for output mode in ?gpio-direction? (address 73). b. gpio3 is set for pwm mode in ?gpio-pwm? (address 75). c. the ?resolution? field is set to 8-bit in slider-options (address 21). d. finally, a calibration cycle is initiated. 4. if res is not set, the touch status is processed. the states of the discrete touch keys 8 ? 5 from ?key status 2? are returned in qtstatus[2]. key states output by the qt2160 are fully debounced and can be used in an application without further processing. qtstatus[2] is simply written back to ?gpo drive 1? at address 70 and the leds indicate the touch state. 5. if the sdet bit in the ?general status? regi ster is set, the slider touch position in qtstatus[3] is written to ?pwm level? at address 76.
5 10702a?at42?07/08 driving the at42qt2160 5. i 2 c-compatible driver 5.1 i 2 c-compatible communication i 2 c-compatible communication is a major aspect of any program involving the qt2160. some form of i 2 c-compatible driver must be written to handle read and write operations to the device. most current microprocessors include a hardware i 2 c-compatible master function, which could be programmed to efficien tly handle these transfers, but the driver code will always be specific to the hardware. the example code in this app lication note includes a software-based i 2 c-compatible driver using two port pins of the host microcontroller. it could easily be ported to many processor types. the i 2 c-compatible communication sequences used to read and write data to the qt2160 are fully described in the qt2160 datasheet. 5.2 design approach the driver presented here uses bit-banging techniques to manage the i 2 c-compatible interface. the driver is structured in three layers: ? in the bottom layer, code-macros are used to drive the scl and sda pins and to create start and stop conditions on the i 2 c-compatible bus. ? in the middle layer, the sendbyte() and getbyte() functions sequence the transmission and reception of bytes including handling the ack bit. ? in the top layer, the writeqti2c() and readqti2c() functions can be called by an application to transfer one or more bytes to and from the qt2160. note that for the sake of clarity, the driver is simplified (for example, it includes no timeouts). the following sections describe the driver a nd should be read in conjunction with the code listing. 5.3 macros table 5-1 describes the various code macros used to drive the scl and sda pins. any macro that changes the state of a pin includes a fix ed 5 s delay following the edge. the 5 s delay ensures the 100 khz i 2 c-compatible specification is met and results in a bus clock rate of around 66 khz. table 5-1. code macros for the i 2 c-compatible bus functions macro description i2cdelay generates a program-delay to guarantee i 2 c-compatible timing requirements. the constant bus_delay should be adjusted to produce a 5 s delay. sethiscl floats the scl pin. scl is then pulled high by the pull-up resistor. note: the qt2160 may extend the low clock-phase. this means that after floating the pin, the driver wait s until the high state is achieved before continuing. setloscl drives the scl pin low. there is no need to wait for the pin to achieve the low state. sethisda floats the sda pin. sda is then pu lled high by the pull-up resistor. after floating the pin, the driver wa its until the high state is achieved before continuing.
6 10702a?at42?07/08 driving the at42qt2160 5.4 sendbyte() the sendbyte() function transmits a single byte onto the i 2 c-compatible bus. the byte is supplied as an input parameter. sendbyte() returns i2c_ok if the byte is acknowledged or i2c_fail if a nack is returned. 5.5 getbyte() the getbyte() function receives a single byte and terminates it with either ack or nack. nack should be specified for the last byte of an i 2 c-compatible read transfer. getbyte() returns the received byte. 5.6 writeqti2c() the flowchart for the writeqti2c() function is shown in figure 5-1 . figure 5-1. flowchart for the writeqti2c() function setlosda drives the sda pin low. there is no need to wait for the pin to achieve the low state. floatsda this simply floats the sda pin so that the qt2160 can drive sda during data-reads or ack cycles. sendstart outputs the start condition sendstop outputs the stop condition sendclock pulses the scl pin high-low table 5-1. code macros for the i 2 c-compatible bus functions (continued) macro description writeqti2c() send i2c start result? send (slave-address + write) send i2c stop ok fail result? send (write-address) ok fail length = 0? yes no decrement length send (next data byte) send i2c stop return result
7 10702a?at42?07/08 driving the at42qt2160 the writeqti2c() function writes one or more bytes to the qt2160 as specified in the datasheet. it accepts four input parameters: ? slaveaddress: the qt2160 i 2 c-compatible address as selected at pins i2ca1 and i2ca0. ? writeaddress: the address of the first qt2160 register to be written. ? writelength: the number of bytes to be written. ? writeptr: a pointer to the first byte to be written. the pointer should point to a byte array. the function returns i2c_ok if the entire write transfer is acknowledged (ack), or i2c_fail if a nack is returned. 5.7 readqti2c() the flowchart for readqti2c() is shown in figure 5-2 . figure 5-2. flowchart for the readqti2c() function the readqti2c() function reads one or more byte s to the qt2160 as specified in the datasheet. it accepts four input parameters: ? slaveaddress: the qt2160 i 2 c-compatible address as selected at pins i2ca1 and i2ca0. ? readaddress: the address of the first qt2160 register to be read. ? readlength: the number of bytes to be read. ? readptr: a pointer to a byte-array where the read data should be saved. the function returns i2c_ok if the entire read transfer is completed correctly. note that the writeqti2c() function is called to set the address-pointer within the qt2160. readqti2c() send i2c start result? send (slave-address + read) send i2c stop ok fail length = 0? yes no decrement length read (next data byte) send i2c stop return result write address-pointer using writeqti2c() result? ok fail
8 10702a?at42?07/08 driving the at42qt2160 6. source code /*===================================================================================== project: at42qt2160-mmu example code =====================================================================================*/ typedef unsigned char uint8_t; enum { /* qt2160 registers */ qt_chip_id = 0, qt_code_version, qt_general_status, qt_key_status_1, qt_key_status_2, qt_slider_position, qt_gpio_read, qt_calibrate = 10, qt_reset, qt_lp_mode, qt_awake_timeout = 14, qt_neg_drift_comp, qt_pos_drift_comp, qt_di_limit, qt_neg_recal_delay, qt_drift_hold_time, qt_slider_control, qt_slider_options, qt_key_control, qt_key_nthr = 38, qt_key_bl = 54, qt_gpo_drive = 70, qt_gpio_drive, qt_gpio_dir = 73, qt_gpo_pwm, qt_gpio_pwm, qt_pwm_level, qt_gpio_wake, qt_comm_chg_keys_1, qt_comm_chg_keys_2 }; #define qt2160_id 0x11 /* chip id (read from device-address 0) */ #define qt_status_sdet 0x01 /* bitmask for slider-detect bit at device-address 2 */ #define qt_status_res 0x80 /* bitmask for reset bit at device-address 2 */ #define qt_gpio_1 0x04 /* bitmask for gpio1 */ #define qt_gpio_2 0x08 /* bitmask for gpio2 */ #define qt_gpio_3 0x10 /* bitmask for gpio3 */ #define slider_8bit_res 0x00 /* 8-bit resolution (written to device-address 21) */ #define change_asserted_low 0 /* asserted state for /change pin */ #define qt2160_i2c_address 0x0d /* i2c address used by demo. i2ca1 = i2ca0 = 0 */ uint8_t qtstatus[5]; /* application storage for qt2160 device-status */ uint8_t qtdata; /* data buffer used for single-byte read and write transfers */ /* port-assignment for qt2160-interface pins */ sbit scl = p0 ^ 7; sbit sda = p0 ^ 6; sbit change_pin = p0 ^ 3; /* i2c driver ? function prototypes */ uint8_t writeqti2c ( uint8_t slaveaddress, uint8_t writeaddress, uint8_t writelength, uint8_t *writeptr ); uint8_t readqti2c ( uint8_t slaveaddress, uint8_t readaddress, uint8_t readlength, uint8_t *readptr );
9 10702a?at42?07/08 driving the at42qt2160 /*===================================================================================== function: main() =====================================================================================*/ void main ( void ) { /*------------------------------- initialisation -------------------------------------*/ /* (1) establish communication with the qt2160 touch-sensor */ /* wait for successful transfer at the qt2160's address - read chip-id */ while ( !readqti2c (qt2160_i2c_address, qt_chip_id, 1, &qtdata) ); /* (2) check that the responding device is a qt2160! */ while ( qtdata != qt2160_id ); /*------------------------ end of initialisation -------------------------------------*/ /*------------------------ main loop -------------------------------------------------*/ while (1) { if ( change_pin == change_asserted_low ) /* test /change pin */ { /* if /change is asserted, read all status-bytes */ readqti2c ( qt2160_i2c_address, qt_general_status, 5, qtstatus ); /* reading these registers will restore /change pin to the inactive (hi) state */ /* has device just reset? */ if ( qtstatus[0] & qt_status_res ) { /* after any reset, configure device for demo requirements: the demo uses power-up default values for all touch-related registers. all keys are enabled by default and the slider is set to use 5-keys. */ qtdata = qt_gpio_3; /* set gpio3 for output mode */ writeqti2c ( qt2160_i2c_address, qt_gpio_dir, 1, &qtdata ); /* configure gpio3 for pwm mode */ writeqti2c ( qt2160_i2c_address, qt_gpio_pwm, 1, &qtdata ); /* configure slider for 8-bit resolution */ qtdata = slider_8bit_res; writeqti2c ( qt2160_i2c_address, qt_slider_options, 1, &qtdata ); /* send calibrate command */ qtdata = 1; writeqti2c ( qt2160_i2c_address, qt_calibrate, 1, &qtdata ); }
10 10702a?at42?07/08 driving the at42qt2160 else { /* write key-states back to the qt2160 leds */ writeqti2c ( qt2160_i2c_address, qt_gpo_drive, 1, &qtstatus[2] ); /* update the pwm level if the slider is touched */ if (qtstatus[0] & qt_status_sdet) writeqti2c ( qt2160_i2c_address, qt_pwm_level, 1, &qtstatus[3] ); } /* end if ( qtstatus[0] & qt_status_res ) */ } /* end if ( change_pin.. ) */ } /* end while (1) */ /*------------------------ end of main loop -----------------------------------------*/ } /*------------------------------ i2c driver -----------------------------------------*/ /* the following code is the i2c driver */ /* ------------ i2c driver defines --------------- */ #define ack 0 #define nack 1 #define i2c_ok 1 #define i2c_fail 0 #define read_flag 0x01 #define bus_delay 23 /*------------ i2c code macros ------------------- */ #define i2cdelay for (i = 0; i < bus_delay; i++) #define sethiscl {scl = 1; while (!scl); i2cdelay;} #define setloscl {scl = 0; i2cdelay;} #define sethisda {sda = 1; while (!sda); i2cdelay;} #define setlosda {sda = 0; i2cdelay;} #define floatsda {sda = 1;} #define sendstart {setlosda; setloscl;} #define sendstop {setlosda; sethiscl; sethisda;} #define sendclock {sethiscl; setloscl;} /*----------------------------------------------- */
11 10702a?at42?07/08 driving the at42qt2160 /*===================================================================================== function: sendbyte() input: byte to send output: i2c_ok if device acks, i2c_fail if device nacks ====================================================================================*/ uint8_t sendbyte ( uint8_t txbyte ) { uint8_t i,b, result = i2c_ok; for (b = 0; b < 8; b++) { if ( txbyte & 0x80 ) sethisda else setlosda sendclock txbyte <<= 1; /* shift out data byte */ } floatsda /* prepare to receive ack bit */ sethiscl /* read ack bit */ if ( sda == 1 ) result = i2c_fail; setloscl return result; } /*===================================================================================== function: getbyte() input: state of ack bit to send output: received byte ====================================================================================*/ uint8_t getbyte ( uint8_t ackbit ) { uint8_t i,b, rxbyte = 0; floatsda for (b = 0; b < 8; b++) { rxbyte <<= 1; /* shift in data byte */ sethiscl;
12 10702a?at42?07/08 driving the at42qt2160 if ( sda ) rxbyte |= 1; setloscl; } if ( ackbit ) /* send ack bit */ setlosda else sethisda sendclock return rxbyte; } /*===================================================================================== function: writeqti2c() executes multi-byte write to qt-device input: slaveaddress = device address on the i2c bus writeaddress = register address writelength = number of bytes to write writeptr = pointer to byte array containing write-data output: i2c_ok if transfer completes, i2c_fail if device nacks ====================================================================================*/ uint8_t writeqti2c ( uint8_t slaveaddress, uint8_t writeaddress, uint8_t writelength, uint8_t *writeptr ) { uint8_t i, result; do { /* attempt to address device until ack is received */ sendstart; if ( (result = sendbyte ( slaveaddress << 1 )) != i2c_ok ) sendstop; } while ( result != i2c_ok ); /* write address-pointer to device */ result = sendbyte ( writeaddress ); while ( (result == i2c_ok) && writelength-- ) result = sendbyte ( *writeptr++ ); sendstop; /* terminate transfer */ return result; }
13 10702a?at42?07/08 driving the at42qt2160 /*===================================================================================== function: readqti2c() executes multi-byte read from qt-device input: slaveaddress = device address on the i2c bus readaddress = register address readlength = number of bytes to read readptr = pointer to byte array for read-data output: i2c_ok if transfer completes, i2c_fail if device nacks ====================================================================================*/ uint8_t readqti2c ( uint8_t slaveaddress, uint8_t readaddress, uint8_t readlength, uint8_t *readptr ) { uint8_t i, result; /* write address-pointer to device */ result = writeqti2c ( slaveaddress, readaddress, 0, 0 ); if ( result == i2c_ok ) { do { /* attempt to address device until ack is received */ sendstart; if ( (result = sendbyte ( (slaveaddress << 1) + read_flag) ) != i2c_ok ) sendstop; } while ( result != i2c_ok ); do { *readptr++ = getbyte ( --readlength ); } while ( readlength ); sendstop; /* terminate transfer */ } return result; } /*--------------------------end of i2c driver ---------------------------------------*/
10702a?at42?07/08 headquarters international atmel corporation 2325 orchard parkway san jose, ca 95131 usa tel: 1(408) 441-0311 fax: 1(408) 487-2600 atmel asia room 1219 chinachem golden plaza 77 mody road tsimshatsui east kowloon hong kong tel: (852) 2721-9778 fax: (852) 2722-1369 atmel europe le krebs 8, rue jean-pierre timbaud bp 309 78054 saint-quentin-en- yvelines cedex france tel: (33) 1-30-60-70-00 fax: (33) 1-30-60-71-11 atmel japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel: (81) 3-3523-3551 fax: (81) 3-3523-7581 touch technology division 1 mitchell point ensign way hamble southampton hampshire so31 4rf united kingdom tel: (44) 23-8056-5600 fax: (44) 23-8045-3939 product contact web site www.atmel.com technical support qprox.support@atmel.com sales contact qprox.sales@atmel.com literature requests www.atmel.com/literature disclaimer: the information in this document is provided in connection with atmel and qrg ltd. products. no license, express or implied, b y estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel or qrg ltd. products. except as set forth in atmel?s terms and conditions of sale located on atmel?s web site where atmel is the seller or qrg ltd.?s conditions of sale and provi- sion of services where qrg ltd. is the seller, atmel and qrg ltd. assume no liability whatsoever and disclaim any express, implied or statutory warranty relating to its products including, but not limited to, the implied warranty of merchantability, fitness for a particular purpose, or non-infringement. in no event shall atmel or qrg ltd. be liable for any direct, indirect, consequential, punitive, special or incidental damages (including, without limitation, damages for loss and profits, business interruption, or loss of inform ation) arising out of the use or inability to use this document, even if atmel and qrg ltd. have been advised of the possibility of such damages. atmel and qrg ltd. make no representations or warranties with respect to the accuracy or complete- ness of the contents of this document and reserve the right to ma ke changes to specif ications and product descriptions at any t ime without notice. atmel and qrg ltd. do not make any commitment to update the information cont ained herein. unless specifically provided otherwise, atmel and q rg ltd. products are not approved for use in automotive applications, medical applications (incl uding, but not limited to, life support systems and other medical equipment), avionics, nuclear applica- tions, or other high risk applications (e.g., applications that, if they fail, can be reasonably expected to result in signific ant personal injury or death). ? 2008 atmel corporation. all rights reserved. atmel ? , logo and combinations thereof, and ot hers are registered trademarks, qslide ? , qmatrix ? , qtouch ? and others are trademarks of atmel corporation or its subsidiaries. other terms and product names may be trademarks of others.


▲Up To Search▲   

 
Price & Availability of AT42QTAN0040

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X